﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Common.Utlis;

namespace Common.Utils
{
    /// <summary>
    /// 不实时关闭的StreamWriter
    /// </summary>
    public class StreamWriterHelp
    {
        public Encoding Encoding=Encoding.UTF8;

        public Dictionary<string,StreamWriter> DictStreamWriters=new Dictionary<string, StreamWriter>();


        public StreamWriterHelp()
        {
          
        }

        public void WriteValue(string path, string value)
        {
            lock (path)
            {
                if (!DictStreamWriters.TryGetValue(path, out StreamWriter streamWriter))
                {
                    streamWriter= new StreamWriter(path, true, Encoding.UTF8);
                    DictStreamWriters.Add(path,streamWriter);
                }
             
                streamWriter.Write(value);
                streamWriter.Flush();
            }
        }




    }

    /// <summary>
    /// 释放写的消息
    /// </summary>
   [Serializable]
    public class DisposeStreamWriterMsg
    {

    }
}
